package com.samapp.map;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.samapp.R;
import com.samapp.entity.Client;

public class ClientAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<Client> mClients;

	public ClientAdapter(Context context, List<Client> mClients) {
		this.mInflater = LayoutInflater.from(context);
		this.mClients = mClients;
	}

	@Override
	public int getCount() {
		return mClients.size();
	}

	@Override
	public Object getItem(int position) {
		return mClients.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.client_item, parent, false);
			holder = new ViewHolder();
			holder.number = (TextView) convertView.findViewById(R.id.textview_number);
			holder.cname = (TextView) convertView.findViewById(R.id.textview_cname);
			holder.ccontacts = (TextView) convertView.findViewById(R.id.textview_ccontacts);
			holder.phone = (TextView) convertView.findViewById(R.id.textview_phone);
			holder.mobile = (TextView) convertView.findViewById(R.id.textview_mobile);
			holder.addresscn = (TextView) convertView.findViewById(R.id.textview_addresscn);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Client mClient = mClients.get(position);
		holder.number.setText(mClient.getNumber());
		holder.cname.setText(mClient.getCname());
		holder.ccontacts.setText(mClient.getCcontacts());
		holder.phone.setText(mClient.getPhone());
		holder.mobile.setText(mClient.getMobile());
		holder.addresscn.setText(mClient.getAddresscn());
		return convertView;
	}

	private class ViewHolder {
		TextView number;
		TextView cname;
		TextView ccontacts;
		TextView phone;
		TextView mobile;
		TextView addresscn;
	}
}
